#!/bin/bash

echo $1
cd $1 || exit
STATUS_RESULT=$(git status | sed -n "4, 1p" | awk '{print $1}')
#echo "$STATUS_RESULT"
if [ "Untracked" = "$STATUS_RESULT" ] || [ "Changes" = "$STATUS_RESULT" ] 
then
  echo "有文件变更，执行提交"
  #执行提交
  echo "$STATUS_RESULT"
  current_time=$(date "+%Y-%m-%d %H:%M:%S")
  echo $current_time
  dos2unix -q *
  git add .
  git commit -m "auto commit at $current_time"
  git pull
  git push
else
  git pull
fi
if [ "nothing" = "$STATUS_RESULT" ]; then
  echo "$STATUS_RESULT"
fi
